package com.syt.dome.controller;

import com.syt.commer.Result;
import com.syt.dome.service.HospitalService;
import com.syt.entity.model.hosp.Hospital;
import com.syt.entity.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/syt/hosp/hospital")
//@CrossOrigin// 跨域  使用了网关就不需要这个了
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;











    // 医院列表 (条件查询带分页)
    @ApiOperation(value = "医院列表模块")
    @GetMapping("list/{page}/{limit}")
    public Result listHospitalList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hospitalQueryVo", value = "查询对象", required = false)
             HospitalQueryVo hospitalQueryVo
            //@RequestParam Map<String, Object> map
    ) {

//       String hosname=  map.get("hosname").toString();
//        hospitalQueryVo.setHosname(hosname);
//        System.out.println("11111111111111111111111"+map);
        // 查询
        Page pageModel= hospitalService.selectHospPage(page, limit, hospitalQueryVo);

        System.out.println("查询的医院名称"+hospitalQueryVo);
        List<Hospital> content = pageModel.getContent();

        long totalElements = pageModel.getTotalElements();

        System.out.println("*********************************"+content);
        return Result.ok(pageModel);


    }

/*
    //医院列表(条件查询分页)
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pageModel = hospitalService.selectHospPage(page,limit,hospitalQueryVo);
        List<Hospital> content = pageModel.getContent();
        long totalElements = pageModel.getTotalElements();

        return Result.ok(pageModel);
    }

*/


    // 更新操作
    @ApiOperation(value = "更新上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result lock(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable("id") String id,
            @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
            @PathVariable("status") Integer status){
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }


/*    // 更新上线状态
    @ApiOperation(value = "更新医院的上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id, status);
        return Result.ok();

    }*/





//    查看医院详情信息
    @ApiOperation(value = "获取医院详情")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable String id){

        Map<String, Object> map=hospitalService.getHospById(id);
        return Result.ok(map);

    }



/*
    @ApiOperation(value = "获取医院详情")
    @GetMapping("show/{id}")
    public Result show(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable String id) {
        return Result.ok(hospitalService.show(id));
    }
*/



}
